/*
 *
 *  * | Licensed 未经许可不能去掉「OPENIITA」相关版权
 *  * +----------------------------------------------------------------------
 *  * | Author: xw2sy@163.com
 *  * +----------------------------------------------------------------------
 *
 *  Copyright [2024] [OPENIITA]
 *
 *  Licensed under the Apache License, Version 2.0 (the "License");
 *  you may not use this file except in compliance with the License.
 *  You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 *  Unless required by applicable law or agreed to in writing, software
 *  distributed under the License is distributed on an "AS IS" BASIS,
 *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 *  See the License for the specific language governing permissions and
 *  limitations under the License.
 * /
 */

package cc.iotkit.manager.controller;

import cc.iotkit.common.api.PageRequest;
import cc.iotkit.common.api.Paging;
import cc.iotkit.common.api.Request;
import cc.iotkit.common.constant.TenantConstants;
import cc.iotkit.common.log.annotation.Log;
import cc.iotkit.common.log.enums.BusinessType;
import cc.iotkit.common.validate.AddGroup;
import cc.iotkit.common.validate.EditGroup;
import cc.iotkit.common.web.core.BaseController;
import cc.iotkit.manager.dto.bo.device.DevicePartsBo;
import cc.iotkit.manager.dto.vo.deviceparts.DevicePartsVo;
import cc.iotkit.manager.service.IDevicePartsService;
import cn.dev33.satoken.annotation.SaCheckPermission;
import cn.dev33.satoken.annotation.SaCheckRole;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * 配件清单
 *
 * @author Michelle.Chung
 */
@Validated
@RequiredArgsConstructor
@RestController
@RequestMapping("/device/parts")
@Api(tags = "配件清单")
public class DevicePartsController extends BaseController {

    private final IDevicePartsService service;

    /**
     * 查询分页列表
     */
    @ApiOperation("查询分页列表")
    @SaCheckPermission("device:parts:list")
    @PostMapping("/pageing_list")
    public Paging<DevicePartsVo> queryPageList(@Validated @RequestBody PageRequest<DevicePartsBo> query) {
        return service.queryPageList(query);
    }

    /**
     * 查询列表
     */
    @ApiOperation("查询列表")
    @SaCheckPermission("device:parts:list")
    @PostMapping("/list")
    public List<DevicePartsVo> queryList(@Validated @RequestBody Request<DevicePartsBo> query) {
        return service.queryList(query.getData());
    }

    /**
     * 新增
     */
    @ApiOperation("新增")
    @SaCheckPermission("device:parts:add")
    @Log(title = "设备清单", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    public void add(@Validated(AddGroup.class) @RequestBody Request<DevicePartsBo> bo) {
        DevicePartsBo data = bo.getData();
        service.save(data);
    }

    /**
     * 修改
     */
    @ApiOperation("修改")
    @SaCheckPermission("device:parts:edit")
    @Log(title = "设备清单", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    public void edit(@Validated(EditGroup.class) @RequestBody Request<DevicePartsBo> bo) {
        DevicePartsBo data = bo.getData();

        service.save(data);
    }



    /**
     * 删除
     */
    @ApiOperation("删除")
    @SaCheckPermission("device:parts:remove")
    @Log(title = "设备清单", businessType = BusinessType.DELETE)
    @PostMapping("/delete")
    public void remove(@Validated @RequestBody Request<List<Long>> bo) {
        service.deleteByIds(bo.getData());
    }


}
